<template>
	<view class="container">
		<view class="top-container">
			<image class="bg-img" src="/static/images/my/info_bg.jpg"></image>
			<view v-show="!isLogin" class="user-wrapper">
				<navigator url="/pages/login/login/login" hover-class="opcity" :hover-stay-time="150" class="user">
					<image class="avatar-img" src="/static/images/my/mine_def_touxiang_3x.png"></image>
					<text class="user-info-mobile">请登录</text>
				</navigator>
			</view>
			<view v-show="isLogin" class="user">
				<image class="avatar-img" :src="userinfo.headimageurl"></image>
				<view class="user-info-mobile">
					<text>{{ userinfo.nickname }}</text>
				</view>
			</view>
		</view>
		<view class="tui-userinfo-box" >
			<tui-list-cell :arrow="true" @click="tapEvent(1)">
				<view>
					<tui-icon name="order" :size="16" color="#333" style="margin-right: 20rpx"></tui-icon>
					<text>我的订单</text>
				</view>
			</tui-list-cell>
			<tui-list-cell :arrow="true" @click="tapEvent(2)" v-if="isLogin">
				<view>
					<tui-icon name="shop" :size="16" color="#333" style="margin-right: 20rpx"></tui-icon>
					<text>我是商户</text>
				</view>
			</tui-list-cell>
			<tui-list-cell  >
				<!-- <view style="padding-top:8rpx;padding-bottom:8rpx;"> -->
					
					<button  open-type="share" style="font-size: 28rpx;background-color: #fff;padding:0;width:100%;">
						<tui-icon name="partake" color="#eb0909" :size="14" style="margin-right:10rpx"></tui-icon><text style="color:#eb0909">分享给好友</text>
					</button>
				<!-- </view> -->
			</tui-list-cell>
		</view>
		<!--tabbar-->
		<view class="tui-logout" >
			<tui-button height="88rpx" shadow :size="30" type="warning" shape="circle" plain open-type="contact">联系客服</tui-button>
			<tui-button v-if="isLogin" height="88rpx" shadow :size="30" type="warning" shape="circle" @click="doLogout" margin="20rpx 0 0 0">退出</tui-button>
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	import {
		mapMutations
	} from "vuex";
	export default {
		computed: mapState(["isLogin", "userinfo"]),
		data() {
			return {
				info: null,
			};
		},
		onShow: function() {
			
			if(this.isLogin){
				this.getUserinfoDetail();
			}
			
		},
		onShareAppMessage(res) {
		  if (res.from === 'button') {// 来自页面内分享按钮
		    console.log(res.target)
		  }
		  return {
		    title: '先领券再下单,好评拿红包,天天半价吃外卖',
		  }
		},
		methods: {
			...mapMutations(['setMobile','logout']),  
			getUserinfoDetail() {
				this.loadding = true;
				this.tui
					.request("/api/user/info", "GET", {}, false, false, true)
					.then((res) => {
						this.info = res.data;
						
						this.setMobile(res.data.mobile);
						
					});
			},
			doLogout: function() {
				this.tui.modal("提示", "确定退出登录？", true, (res) => {
					if (res) {
						uni.clearStorage();
						this.logout()
						// uni.reLaunch({
						// 	url: "/pages/login/login/login",
						// });
					}
				});
			},
			
			tapEvent: function(index) {
				let url = "";
				if (index == 1) {
					url = "/pages/order/orderList";
				} else if (index == 2) {
					url = "/pages/myshops/myshops";
				} else {
					
				}
				console.log(url);
				uni.navigateTo({
					url: url,
				});
			},
		},
		onShare(){
			uni.share({
				provider: "weixin",
				scene: "WXSceneSession",
				type: 1,
				summary: "我正在使用冲鸭外卖便利店，赶紧跟我一起来体验！",
				success: function(res) {
					console.log("success:" + JSON.stringify(res));
				},
				fail: function(err) {
					console.log("fail:" + JSON.stringify(err));
				}
			});
			
		},
		onNavigationBarButtonTap(e) {
			if (e.index === 0) {
				// #ifdef APP-PLUS
				const subNVue = uni.getSubNVueById("share");
				subNVue.show("slide-in-bottom", 250);
				// #endif
			}
		},
	};
</script>

<style>
	.container {
		position: relative;
		padding-bottom: 100rpx;
	}

	.top-container {
		height: 260rpx;
		position: relative;
		display: flex;
		flex-direction: column;
	}

	.bg-img {
		position: absolute;
		width: 100%;
		height: 260rpx;
	}

	.tui-logout {
		width: 100%;
		position: fixed;
		left: 0;
		bottom: 100rpx;
		z-index: 999;
		padding: 10rpx 25rpx 15rpx;
		box-sizing: border-box;
	}

	.logout {
		width: 110rpx;
		height: 36rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		margin: 42rpx 0 24rpx 32rpx;
		position: relative;
		z-index: 2;
	}

	.logout-img {
		width: 36rpx;
		height: 36rpx;
		margin-right: 11rpx;
	}

	.logout-txt {
		font-size: 28rpx;
		color: #fefefe;
		line-height: 28rpx;
	}

	.user-wrapper {
		display: flex;
		justify-content: center;
		position: relative;
		z-index: 2;
	}

	.user {
		display: flex;
		flex-direction: column;
		justify-content: center;
		position: relative;
		z-index: 2;
	}

	.avatar-img {
		width: 160rpx;
		height: 160rpx;
		border-radius: 50%;
		align-self: center;
		margin-top: 30rpx;
	}

	.user-info {
		display: flex;
		flex-direction: row;
		margin-top: 30rpx;
		align-items: center;
	}

	.user-info-mobile {
		margin-top: 15rpx;
		position: relative;
		font-size: 28rpx;
		color: #fefefe;
		line-height: 28rpx;
		align-self: center;
		padding: 0 50rpx;
	}

	.edit-img {
		position: absolute;
		width: 42rpx;
		height: 42rpx;
		right: 0;
		bottom: -4rpx;
	}

	.edit-img>image {
		width: 42rpx;
		height: 42rpx;
		padding-left: 25rpx;
	}

	.middle-container {
		height: 138rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		border-radius: 10rpx;
		background-color: #ffffff;
		margin: -30rpx 30rpx 26rpx 30rpx;
		box-shadow: 0 15rpx 10rpx -15rpx #efefef;
		position: relative;
		z-index: 2;
	}

	.middle-item {
		height: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.ticket-img {
		width: 80rpx;
		height: 80rpx;
		margin-left: 65rpx;
	}

	.middle-tag {
		font-size: 28rpx;
		color: #333333;
		line-height: 28rpx;
		font-weight: bold;
		padding-left: 22rpx;
	}

	.car-img {
		width: 80rpx;
		height: 80rpx;
		margin-left: 97rpx;
	}

	.bottom-container {
		height: 334rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		padding: 40rpx 74rpx 40rpx 95rpx;
		margin: 0 30rpx;
		background-color: #ffffff;
		border-radius: 10rpx;
		box-sizing: border-box;
		box-shadow: 0 0 10rpx #efefef;
	}

	.ul-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.item {
		display: flex;
		flex-direction: column;
		align-items: center;
		position: relative;
	}

	.item-img {
		width: 32rpx;
		height: 32rpx;
	}

	.item-name {
		padding-top: 13rpx;
		font-size: 24rpx;
		color: #666666;
		min-width: 80rpx;
		text-align: center;
	}

	.btn-feedback {
		background: transparent !important;
		position: absolute;
		height: 100%;
		width: 100%;
		left: 0;
		top: 0;
		border: 0;
	}

	.btn-feedback::after {
		border: 0;
	}

	.tui-userinfo-box {
		margin: 10rpx 0;
		color: #333;
	}

	.tui-list-cell {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		/* padding: 24rpx 60rpx 24rpx 30rpx; */
		box-sizing: border-box;
		font-size: 30rpx;
	}

	.tui-content {
		font-size: 26rpx;
		color: #666;
	}
</style>
